package com.collect.common.utils.ik;

import org.apache.commons.lang3.StringUtils;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @ Author :hky
 * @ Date  : Created in 15:11 2022-09-21
 * @ Version discord
 * @ Decribtion : $
 */
public class IKAnalyzerSupport {
    public static List<String> iKSegmenterToList(String string){
        List<String> list=new ArrayList<>();
        try{
            if(StringUtils.isEmpty(string)){
                return list;
            }
            StringReader sr=new StringReader(string);
            IKSegmenter ik=new IKSegmenter(sr, true);
            Lexeme lex;
            while((lex=ik.next())!=null){
                String lexemeText=lex.getLexemeText();
                list.add(lexemeText.toLowerCase());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
}
